/**
 * 
 */
package it.irondev.appturismo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import it.irondev.appturismo.dao.RouteMapper;
import it.irondev.appturismo.dao.RoutestagesMapper;
import it.irondev.appturismo.entity.Route;
import it.irondev.appturismo.entity.Routestages;
import it.irondev.appturismo.entity.RoutestagesExample;
import it.irondev.appturismo.service.IRouteService;

/**
 * @author federicocerruto
 *
 */
@Service
public class RouteServiceImpl implements IRouteService {

	@Autowired
	RouteMapper routeDao;
	
	@Autowired
	RoutestagesMapper stageDao;
	
	
	
	public Route getRouteById(Integer idRoute) {
		return routeDao.selectByPrimaryKey(idRoute);
	}

//	@Transactional
	public void addRoute(Route route) {
		routeDao.insert(route);
		for(Routestages stage:route.getStages())
			stageDao.insert(stage);
	}
	

	
	public List<Route> getAllRoutes() {
		return routeDao.selectByExample(null);
	}

	
	public void updateRoute(Route route) {
		 routeDao.updateByPrimaryKey(route);
	}

	
	public void deleteRoute(Integer idRoute) {
		routeDao.deleteByPrimaryKey(idRoute);
	}

	
	public List<Routestages> getRouteStages(Integer idRoute) {
		RoutestagesExample example = new RoutestagesExample();
		example.createCriteria().andRouteEqualTo(idRoute);
		return stageDao.selectByExample(example);
	}

	
	public void updateRouteStages(List<Integer> idRouteStages) {
		//TODO:
	}

}
